This is a race bug.
The expected exception is a RuntimeException.
More details about this bug are at
JDK-7045594 JIRA page.
java.util.logging.Logger
t1 t2 public static Logger getLogger(String name, String resourceBundleName) {
LogManager manager = LogManager.getLogManager();
1 3 Logger result = manager.demandLogger(name);
2 4 if (result.resourceBundleName == null) {
// Note: we may get a MissingResourceException here.
5 6 result.setupResourceInfo(resourceBundleName);
} else if (!result.resourceBundleName.equals(resourceBundleName)) {
throw new IllegalArgumentException(result.resourceBundleName +
" != " + resourceBundleName);
}
7 8 return result;
}
Preconditions:
Two threads call getLogger with the same name and different resourceBundleName.
t1:Logger logger1=Logger.getLogger("test", "bar");
t2:Logger logger2=Logger.getLogger("test","foo");
a) thread 1 get a new instance of result at 1.
b) result.resourceBundleName in thread 1 is null at 2.
c) before thread 1 continues, context switched, at 3 thread 2 gets the same result as thread 1 got in step a).
d) result.resourceBundleName in thread 2 is null at 4.
e) context switched, thread 1 set "bar" at 5.
f) context switched, thread 2 set "foo" at 6.
g) now, thread 1's resourceInfo has been over written by thread 2.
h) thread 1 return result at 7 and then thread 2 return result at 8.
This bug is reproduced under JDK 1.7.0.
It started at JDK 1.7.0, and has been fixed since JDK 1.8.0.
Execute the following scripts to run the test to reproduce the bug (assume the location of the jdk7 test project is jdk7_test_home).
Linux:
${jdk7_test_home}/scripts/7045594.sh [--javaloc path]
Windows:
%jdk7_test_home%\scripts\7045594.bat [--javaloc path]
| Option | Function |
| --javaloc | The location of JDK that is eligible to reproduce the bug, if your java environment is not eligible.
In this case, it's JDK 1.7.0. It should be the absolute path to the JDK's java starter and ended with "/". For example: ~/jdk/home/jdk1.7.0/bin/ |